/*
题目描述：和为 s 的两个数字
方法：
两个指针解决问题
 */
public class E57_1 {
    public static void main(String[] args) {
        int[] array = {1,2,4,7,11,15};
        int sum = 15;
        int[] num1 = new int[1];
        int[] num2 = new int[1];
        if(FindNumbersWithSum(array, sum, num1, num2)){
            System.out.println(num1[0] + " " + num2[0]);
        }
    }

    public static boolean FindNumbersWithSum(int[] array, int sum, int[] num1, int[] num2){
        boolean found = false;
        if(array == null || array.length <= 0 || num1 == null || num2 == null){
            return found;
        }
        int right = array.length - 1;
        int left = 0;

        while(right > left){
            int curSum = array[left] + array[right];

            if(curSum == sum){
                num1[0] = array[left];
                num2[0] = array[right];
                found = true;
                break;
            }
            else if(curSum > sum){
                right --;
            }
            else{
                left ++;
            }
        }
        return found;
    }
}
